<?php

// n_list.php
// Michael Baker
// 2010.07.12
//
// List nodes

session_start();

define("IN_MDM", true);
define("CUR_PAGE_TITLE", "Node management");
define("CUR_FLAG", "n.list");

include '../includes/all.php';
include 'inc/header.php';

?>
<p>On this page, you are able to manage the perfSONAR network devices (<strong>nodes</strong>) recognized by the E2E system. Nodes belong to <strong>segments</strong>
(which are effectively QoS-classified pairs of nodes), and segments belong to <strong>workflows</strong>. Note that any object that is a dependency of another object cannot
be removed until all such links are broken.<br /><br />To manage a segment, please click one of its corresponding two nodes in the node list.</p>
<div class="nodemap">
<h2>Node map</h2>
<p>Below is a map of all nodes currently in the E2E database. <strong>MP nodes</strong> are shown
with dotted borders; <strong>unused segments</strong> are represented by dotted lines; 
<strong>orphaned nodes</strong> are represented by red borders. Arrow colours represent
the QoS class of the segment to which they correspond.</p>
<br />
<img src="get_net.php" /></div>
<h2>Node list</h2>
<table class="type2p" cellspacing="1">
  <col class="col2" /><col class="col2" /><col class="col2" /><col class="col1" />
  
  <thead>
    <tr>
      <th>Node Title</th>
      <th>Node Name</th>
      <th>Node Address</th>
      <th>Controls</th>
    </tr>
  </thead>
  
  <tbody>
    <?php
    
    $has_n_view = has_flag( $uid, "n.view" );
    $has_n_del  = has_flag( $uid, "n.del" );
    
    // Retrieve ID=>Title assoc. array of workflows
    $n_list = $dbase->list_nodes();
    asort($n_list); // sort alphabetically (use ksort for ID sorting)
    
    foreach ( $n_list as $id => $obj ) {
      
      $title = $obj->get_title();
      $name  = $obj->get_title(0);
      $addr  = $obj->get_address();
      $conn  = count( $dbase->search_for_nodecouples( $id ) );
      
      // Only allow node removal if it has 0 connections (orphan)
      // $deletion_cond = ($has_n_del) && (!$conn);
      $deletion_cond = ($has_n_del);
      $link1 = $has_n_view     ? ui_create_link( $title, "n_view.php?id=$id" ) : $title;
      $link2 = $deletion_cond  ? ui_create_link( "Remove", "n_del.php?id=$id" ) : "Remove";
      
      echo "<tr>";
      echo "<td>$link1</td>";
      echo "<td>$name</td>";
      echo "<td>$addr</td>";
      echo "<td style=\"text-align: center;\">$link2</td>";      
      echo "</tr>";
    }
     
    ?>
  </tbody>
</table>

<?php include 'inc/footer.php'; ?>